home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / emacs16d.zip / FREEMODE.MIN < prev    next >
Text File  |  1992-01-16  |  8KB  |  218 lines

  1. 
  2. From richard@iesd.auc.dk Wed, 15 Jan 1992 11:13:32 EST remote from uupsi
  3. Received:  from uupsi by crynwr.com (UUPC/extended 1.11n) with UUCP;
  4.            Wed, 15 Jan 1992 11:13:32 EST
  5. Received: from iesd.auc.dk by uu.psi.com (5.65b/4.1.011392-PSI/PSINet)
  6.     id AA05097; Wed, 15 Jan 92 10:47:37 -0500
  7. Received: from galilei.iesd.auc.dk by iesd.auc.dk via DENet with SMTP
  8.     (5.61++/IDA-1.2.8) id AA07716; Wed, 15 Jan 92 16:45:08 +0100
  9. Date: Wed, 15 Jan 92 16:45:08 +0100
  10. From: Richard Flamsholt S0rensen <richard@iesd.auc.dk>
  11. Message-Id: <9201151545.AA07716@iesd.auc.dk>
  12. Received: by galilei.iesd.auc.dk (4.1/SMI-4.1)
  13.     id AA15179; Wed, 15 Jan 92 16:45:10 +0100
  14. To: nelson%crynwr@uu.psi.com
  15. In-Reply-To: "Russell Nelson"'s message of Mon, 06 Jan 1992 08:39:33 EST <29685c18.crynwr@crynwr.com>
  16. Subject: More mode business
  17.  
  18.   Hi Russ!
  19.  
  20.   Remember the modes talk?  Well, though you had some plans too, I had
  21. to get my system going and I've actually finally come up with a fine
  22. idea which is backwards compatible with the old mode-functions!
  23.  
  24.   What I've wanted was some kind of distinction between the user
  25. calling M-x foo-mode and Freemacs doing a buffer switch.  Now, the
  26. point is that the user can never supply an argument to that M-x
  27. foo-mode, since they don't start with a tab.  So?  So, if we let the
  28. buffer switching code do something like
  29.  
  30.     #(##(temp),this is a buffer switch)
  31.  
  32. --where ##(temp) is the resolved mode-name, we can internally in every
  33. foo-mode find out whether to start over from scratch with
  34. Fenter-local-mode's and everything or just do some fiddling with
  35. Flocal-bind-key.  The good point is that those that doesn't do so,
  36. well, fine -- they'll just retain their old behaviour (i.e. forgetting
  37. minor modes between buffer switch etc), but they can be changed as
  38. time goes by: they don't *need* to take advantage of this new info.
  39.  
  40.   So what about those that do?  What *should* they do?  They should
  41. of course use it to separate the tasks internally, like
  42.  
  43.     #(==,,arg1,(
  44.         all the usual stuff for setting up a new mode
  45.     ),(
  46.         only buffer switching code goes here
  47.     ))
  48.  
  49. [which ought to be handled by an "official" specialized function like
  50. my Uenter-local-mode, especially because the code done at buffer
  51. switch (local keybindings etc) should also be done at buffer setup,
  52. and this would cause a code duplication in the mode function.]
  53.  
  54.   It's that simple.  OK, actually there's one more thing to go,
  55. because I still have the problem of old minor-modes hanging on when
  56. swithing from one mode to another within the same buffer.  This is
  57. easily coped with: apart from the mode functions only three other
  58. functions, namely
  59.  
  60.     Fvisit-do.
  61.     Ffind-unused-buffer
  62.     Fset-mode-by-ext
  63.  
  64. --actually does cause a *change* of mode in the same buffer: all other
  65. functions (Fswitch-to-buffer, F:other-window etc) doesn't change a
  66. buffer's mode.  Therefore, we'll need to let these three and the mode
  67. functions kill all minor modes.  Since they all call Fexit-mode either
  68. directly or through Fenter-local-mode, it seemed quite natural to
  69. augment Fexit-mode to take an argument: if it is nil (like it is
  70. everywhere now), behave as normal; if non-nil, kill the current
  71. minor-modes.
  72.   This means, that any mode function that wants to follow this idea
  73. should call #(Fexit-mode,#(==,,arg1,kill))  [notice that when the
  74. mode *does not* get an argument, we start from scratch and want it to
  75. kill the minor modes -- it's a bit tricky to remember.]  -- but if we
  76. use a specialized function to encapsulate the function mode body, it
  77. should of course to that bit of work too.
  78.  
  79.  
  80.   So, summa summarum.  If we adapt (at least until you've finished
  81. your work) this idea it all comes down to this:
  82.  
  83.     o  "Old" modes works as before.
  84.     o  Modes that conforms to the idea needs only a very slight
  85.        change (wrap a function call around the body) and will
  86.        then behave properly with respect to minor modes and in
  87.        generel be more flexible and under control.
  88.     o  Only five F-lib functions needs to be changed (in addition,
  89.        also Fexit-mode and Fenter-local-mode should take an arg),
  90.        and they retain compatability with all the old code.
  91.  
  92.  
  93.   I've included my changes at the bottom.  One of the main reasons
  94. why I'm pushing this a bit is because I'm about to loose my account
  95. (I majored in CS last year) and I'd like to distribute at least my
  96. LaTeX-mode, which I've worked on for 2-3 years -- and unless I
  97. surrender and rewrite it a bit, it relies on proper minor mode
  98. handling.  So, I look forward to hear from you.
  99.  
  100.   Richard
  101.  
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104.  
  105. Name:Fenter-local-modes
  106. Given the mode of the current buffer, enter all the local modes, i.e. the major
  107. mode for this buffer, and any minor modes in effect.
  108. RFS:    Changed to use new minor-mode scheme.  If arg1 is "kill", then
  109.     kill all minor modes in effect.  This should be done when changing
  110.     mode in a buffer and not just switching to another well-established
  111.     (mode-wise) buffer.  Actually, only Fvisit-do., Ffind-unused-buffer,
  112.     and Fset-mode-by-ext calls this function with an argument so far,
  113.     since only they alter the mode for the current buffer.
  114. [*]
  115. #(Fexit-mode,##(==,kill,arg1,,dontkill))
  116. #(Fresolve-name,##(buffer-mode.##(ba,-1))-mode,(
  117.     #(#(temp),##(==,kill,arg1,,dontkill))
  118. ))
  119. [*]
  120.  
  121.  
  122. Name:Fexit-mode
  123. This will undo the local mode's changes.  Always resets the syntax table
  124. to Fsyntax.
  125. RFS>    Do a #(ds,syntax,##(Fsyntax)) to define syntax (to please the
  126.     compile code).
  127. RFS>    Undoes/does the effect of any minor modes.  Be sure to do this
  128.     *after* evaluating the local-mode-changes string.  If not given
  129.     an argument, *do* kill all minor-modes in this buffer. This is used
  130.     when changing mode in a buffer: all mode functions should
  131.     therefore do a #(Fexit-mode,arg1) instead of plain #(Fexit-mode),
  132.     so upon M-x foo-mode they'll always kill the local minor-modes,
  133.     while only the buffer-switching code can provide an argument to
  134.     keep the minor-modes save.
  135. RFS>    Checks whether to enter Thorsten Ohl's auto-save mode.
  136. [*]
  137. #(local-mode-changes)
  138. #(ds,local-mode-changes)
  139. #(==,,arg1,(
  140.     #(Uexit-all-minor-modes)
  141.     #(==,##(F-auto-save-default),,,(
  142.         #(F:auto-save-mode,1)
  143.     ))
  144. ),(
  145.     #(Uenter-minor-modes)
  146. ))
  147. #(st,Fsyntax)
  148. #(ds,syntax,##(Fsyntax))
  149. [*]
  150.  
  151.  
  152. Name:Ffind-unused-buffer
  153. RFS:    Fenter-local-modes shall kill the local minor modes.
  154. [*]#(..,#(ba,#(ls,(,),buffer-free.)))
  155. #(n?,buffer-free.##(ba,-1),(
  156.     #(es,buffer-free.##(ba,-1))
  157. ),(
  158.     #(ds,buffer-marks.##(ba,-1),PQRSTUVWXYZ)
  159.     #(pm,-26)
  160. ))
  161. #(Fbuffer-set-fn,arg1)
  162. #(Fset-modename,Fun)
  163. #(Fenter-local-modes,kill)
  164. [*]
  165.  
  166.  
  167. Name:F:Text-mode
  168. Ordinary text mode.
  169. RFS:    Encapsulated the code in a call to Uenter-major-mode.
  170. [*]
  171. #(Uenter-major-mode,arg1,Text,F,emacs,(
  172.     #(Fenter-minor-mode,Fill)
  173. ),(
  174.     #(Flocal-bind-key,K.Tab,F:tab-to-tab-stop)
  175.     #(ds,syntax,##(Fsyntax))
  176.     #(Fmodify-syntax,syntax,##(bc,'),0)
  177.     #(st,syntax)
  178. ))
  179. [*]
  180.  
  181.  
  182. Name:Uenter-major-mode
  183.   Enter the major mode by name of arg2, residing in library arg3 with
  184. library name arg4. arg5 is the code to carry out the first time the
  185. mode is entered and arg6 the code to perform each time we (re-)enter it
  186. (when switching between different buffers).  What about arg1?  Well, it
  187. is simply the arg1 provided to the mode-function that calls this function.
  188.   The function takes care of calling Fexit-mode and setting the mode
  189. name, so the caller doesn't have to worry about that.
  190.   Example:
  191.     #(Uenter-major-mode,arg1,LaTeX,T,tex,(
  192.         #(Fenter-minor-mode,Fill)
  193.         ... other setup/initializing code ...
  194.     ),(
  195.         #(Flocal-bind-key,K.M-q,T:fill-paragraph)
  196.         ... keybindings and things to do on every entry ...
  197.     ))
  198. [*]
  199. #(==,,arg1,(
  200.     #(n?,arg3filename,,(
  201.         #(Fload-lib,arg4)
  202.     ))
  203.     #(n?,arg3filename,(
  204.         #(Fexit-mode,arg1)
  205.         #(Fset-modename,arg2)
  206.         #(Ulocal-ds,mode,arg2)
  207.         arg5
  208.         arg6
  209.     ),(
  210.         #(Ferror,#(env.EMACS)arg4.ed is missing - cannot enter arg2-mode)
  211.     ))
  212. ),(
  213.     #(Fexit-mode,arg1)
  214.     #(Fset-modename,arg2)
  215.     arg6
  216. ))
  217. [*]
  218.